﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using DAL;
using Utility;

public partial class Doanh_Nghiệp_Doanhnghiep_thongtintaikhoan : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            loaddata();
        }
    }

    private void loaddata()
    {
        Label madn = new Label();
        madn.Text=Session["madn"].ToString();
        DoanhNghiep_DTO dn = DoanhNghiep_BUS.GetByID(int.Parse(madn.Text));
        lit_MaSP.Text = dn.MaDN.ToString();
        txttendoanhnghiep.Text = dn.TenDN;
        txtdiachi.Text = dn.DiaChi;
        txtdienthoai.Text = dn.DienThoai;
        txtemail.Text = dn.Email;
        txtfax.Text = dn.Fax;
        txtmatkhau.Text = dn.MatKhau;
        lit_taikhoan.Text = dn.TaiKhoan.ToString();
        img_Hinhanh.ImageUrl = "~/photos/thumb/"+ dn.BanDo;
       
        //Session["hinh"] = dn.BanDo;
    }
    protected void btcapnhat_Click(object sender, EventArgs e)
    {
        try
        {
            DoanhNghiep_DTO doanhnghiep = new DoanhNghiep_DTO();
            Label d = new Label();
            d.Text = Session["madn"].ToString();
            doanhnghiep.MaDN = int.Parse(d.Text);
            doanhnghiep.TenDN = txttendoanhnghiep.Text;
            doanhnghiep.DiaChi = txtdiachi.Text;
            doanhnghiep.DienThoai = txtdienthoai.Text;
            doanhnghiep.Email = txtemail.Text;
            doanhnghiep.Fax = txtfax.Text;
            doanhnghiep.MatKhau = txtmatkhau.Text;
            doanhnghiep.TaiKhoan = int.Parse(lit_taikhoan.Text);
            //if (f_hinhbando.HasFile)
            //{
            //    string filename = DateTime.Now.Ticks.ToString() + "_" + f_hinhbando.FileName;
            //    f_hinhbando.SaveAs(Server.MapPath("~/Photos/" + filename));

            //    System.Drawing.Image img = System.Drawing.Image.FromFile(
            //        Server.MapPath("~/Photos/" + filename));

            //    ImageUtility.MakeThumbnailPhoto(
            //        img, 100, 100, Server.MapPath("~/Photos/Thumb/"), filename);



            //    if (doanhnghiep.BanDo != "no_images.jpg")
            //    {
            //        System.IO.File.Delete(Server.MapPath("~/Photos/" + doanhnghiep.BanDo));
            //        System.IO.File.Delete(Server.MapPath("~/Photos/Thumb/" + doanhnghiep.BanDo));
            //    }
            //    string link = filename;
            //    doanhnghiep.BanDo = link;

            //}
            //else
            //{

            doanhnghiep.BanDo = "no_images.jpg";
            //}
           
            DoanhNghiep_BUS.Update(doanhnghiep);
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message);
        }
        
    }
}
